import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
import dateOpt from '@/biz/option/date.js'

let _this = null


function options(vm, head) {
  _this = vm
  return [
    {
      field: 'customerName',
      minWidth: 120,
      fixed: 'left',
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      }
    },
    {
      field: 'customerPhone',
      minWidth: 130,
      fixed: 'left',
      header: {
        filter: {
          title: '手机号码',
          key: 'customerPhone',
          placeholder: '请输入手机号码',
          input: {}
        }
      }
    },
    {
      field: 'clChannelSourceName',
      minWidth: 160,
      header: {
        filter: {
          title: '线索来源渠道',
          key: 'clChannelSource',
          placeholder: '请选择线索来源渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },

    {
      title: '创建日期',
      field: 'createTime',
      minWidth: 180,

      header: {
        filter: dateOpt.range({
          title: '创建日期',
          placeholder: '请选择创建日期',
          startKey: 'startDate',
          endKey: 'endDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.startDate, val
                .endDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.startDate, val
              .endDate).Y >= 2)
          }
        }),
      },
    },

    {
      field: 'clCounselorName',
      minWidth: 120,
      header: {
        filter: {
          title: '线索顾问',
          key: 'clCounselorId',
          placeholder: '请选择线索顾问',
          load: (o) => {
            o.select.options = clueCustomerMgr.consultants1()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
            remote: (key) => {
              return clueCustomerMgr.selectTeamUser(key)
            }
          }
        },

      },
      slots: {
        default: (params, h) => {
          return [h('div',
            ` ${params.row.isClueVisit =='是'?params.row.clCounselorName:'-'}${params.row.isClueVisit =='是'?'('+ params.row.clCounselorWorkNo+')':''}`
          )]
        }
      }
    },
    {
      field: 'firstContactDate',
      minWidth: 160,
      header: {
        filter: dateOpt.range({
          title: '首触日期',
          placeholder: '请选择首触日期',
          startKey: 'firstContactStartDate',
          endKey: 'firstContactEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.firstContactStartDate, val
                .firstContactEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.firstContactStartDate, val
              .firstContactEndDate).Y >= 2)
          }
        }),
      },


    },
    {
      field: 'clueVisitDate',
      minWidth: 160,
      header: {
        filter: dateOpt.range({
          title: '到访日期',
          placeholder: '请选择到访日期',
          startKey: 'clueVisitStartDate',
          endKey: 'clueVisitEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.clueVisitStartDate, val
                .clueVisitEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.clueVisitStartDate, val
              .clueVisitEndDate).Y >= 2)
          }
        }),
      },
    },

    {
      field: 'visitChannelSourceName',
      minWidth: 160,
      header: {
        filter: {
          title: '到访渠道',
          key: 'visitChannelSource',
          placeholder: '请选择到访渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'isClueVisit',
      title: '是否线索转到访',
      minWidth: 150,
      header: {
        filter: {
          title: '是否线索转到访',
          key: 'isClueVisit',
          placeholder: '请选择',
          select: {
            options: [{
              key: 0,
              value: '否'
            }, {
              key: 1,
              value: '是'
            }]
          }
        }
      },
      slots: {
        default: (params, h) => {
          return [h('div', params.row.isClueVisit)]
        }
      }

    },

    {
      field: 'visitCounselorName',
      minWidth: 120,
      header: {
        filter: {
          title: '到访顾问',
          key: 'visitCounselorId',
          placeholder: '请选择到访顾问',
          load: (o) => {
            o.select.options = clueCustomerMgr.consultants1()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
            // remote: (key) => {
            //   return clueCustomerMgr.selectTeamUser(key)
            // }
          }
        }
      },
      slots: {
        default: (params, h) => {
          return [h('div',
            `${params.row.visitCounselorName}(${params.row.visitCounselorWorkNo})`
          )]
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: 150,
      fixed: 'right',
      align: 'center',
      className: 'conciseContent',
      slots: {
        default: (params, h) => {
          return [h(
            'div', {
              style: {
                display: 'flex',
                flexDirection: 'column',
              },
            },
            [
              h(
                'Button', {
                  props: {
                    type: 'text',
                  },
                  style: {
                    cursor: 'pointer',
                    padding: '0 5px',
                    color: '#0F42A7'
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      _this.detail(params.row)
                    },
                  },
                },
                '查看详情'
              ),
              h(
                'Button', {
                  props: {
                    type: 'text',
                  },
                  style: {
                    color: '#0F42A7',
                    cursor: 'pointer',
                    padding: '0 5px',
                    display: params.row.moreCounselor ? 'block' : 'none'
                  },
                  on: {
                    click: (e) => {
                      _this.moreCounselorRecord(params.row)
                    },
                  },
                },
                '查看更多顾问记录'
              ),
            ]
          )]
        }
      }
    }
  ]
}

export default {
  options
}